package com.effectiv.gooruda.rest.api.operation;

import java.util.Date;
import java.util.List;

import javax.ws.rs.core.MediaType;
import com.effectiv.gooruda.rest.api.domain.Log;
import com.effectiv.gooruda.rest.docs.core.annotation.Api;
import com.effectiv.gooruda.rest.docs.core.annotation.ApiBodyObject;
import com.effectiv.gooruda.rest.docs.core.annotation.ApiHeader;
import com.effectiv.gooruda.rest.docs.core.annotation.ApiHeaders;
import com.effectiv.gooruda.rest.docs.core.annotation.ApiMethod;
import com.effectiv.gooruda.rest.docs.core.annotation.ApiParam;
import com.effectiv.gooruda.rest.docs.core.annotation.ApiRequestParam;
import com.effectiv.gooruda.rest.docs.core.annotation.ApiResponseObject;
import com.effectiv.gooruda.rest.docs.core.pojo.ApiVerb;

@Api(name = "Log API", description = "Save and query log messages.")
public interface LogOperations {

	// yyyy-MM-dd
	@ApiMethod(path = "/api/log/findbetween/{start}/{end}", verb = ApiVerb.GET, description = "Finds all the log entries between a date range.", produces = { MediaType.APPLICATION_JSON }, consumes = { MediaType.APPLICATION_JSON })
	@ApiHeaders(headers = {
			@ApiHeader(name = "signature", description = "Authentication signature."),
			@ApiHeader(name = "public-key", description = "Public key of the application.") })
	@ApiResponseObject
	List<Log> findBetween(
			@ApiParam(name = "start", required = true, description = "Start Date", format = "yyyy-MM-dd") Date start,
			@ApiParam(name = "end", required = true, description = "End Date", format = "yyyy-MM-dd") Date end,
			@ApiRequestParam(name = "pageNo", description = "Search page number.", required = false, defaultValue = "0") int pageNo,
			@ApiRequestParam(name = "pageSize", description = "Number of records to fetch for current page.", required = false, defaultValue = "10") int pageSize);

	@ApiMethod(path = "/api/log/findbylogtext/{text}", verb = ApiVerb.GET, description = "Finds log entries by a given text.Partial text is also allowed.", produces = { MediaType.APPLICATION_JSON }, consumes = { MediaType.APPLICATION_JSON })
	@ApiHeaders(headers = {
			@ApiHeader(name = "signature", description = "Authentication signature."),
			@ApiHeader(name = "public-key", description = "Public key of the application.") })
	@ApiResponseObject
	List<Log> findByLogText(
			@ApiParam(name = "start", required = true, description = "Search text") String text,
			@ApiRequestParam(name = "pageNo", description = "Search page number.", required = false, defaultValue = "0") int pageNo,
			@ApiRequestParam(name = "pageSize", description = "Number of records to fetch for current page.", required = false, defaultValue = "10") int pageSize);

	@ApiMethod(path = "/api/log", verb = ApiVerb.POST, description = "Saves a log entry.", produces = { MediaType.APPLICATION_JSON }, consumes = { MediaType.APPLICATION_JSON })
	@ApiHeaders(headers = {
			@ApiHeader(name = "signature", description = "Authentication signature."),
			@ApiHeader(name = "public-key", description = "Public key of the application.") })
	@ApiResponseObject
	Log save(@ApiBodyObject Log l);

	@ApiMethod(path = "/api/log/findbytype/{type}", verb = ApiVerb.GET, description = "Find long entries by type.", produces = { MediaType.APPLICATION_JSON }, consumes = { MediaType.APPLICATION_JSON })
	@ApiHeaders(headers = {
			@ApiHeader(name = "signature", description = "Authentication signature."),
			@ApiHeader(name = "public-key", description = "Public key of the application.") })
	@ApiResponseObject
	List<Log> findByType(
			@ApiParam(name = "type", required = true, description = "Log message type.", allowedvalues = {
					"DEBUG", "INFO", "ERROR", "FATAL" }) String type,
			@ApiRequestParam(name = "pageNo", description = "Search page number.", required = false, defaultValue = "0") int pageNo,
			@ApiRequestParam(name = "pageSize", description = "Number of records to fetch for current page.", required = false, defaultValue = "10") int pageSize);

	@ApiMethod(path = "/api/log/countbytype/{type}", verb = ApiVerb.GET, description = "Counts the number of log entries by a given type.", produces = { MediaType.APPLICATION_JSON }, consumes = { MediaType.APPLICATION_JSON })
	@ApiHeaders(headers = {
			@ApiHeader(name = "signature", description = "Authentication signature."),
			@ApiHeader(name = "public-key", description = "Public key of the application.") })
	@ApiResponseObject
	long countByType(
			@ApiParam(name = "type", required = true, description = "Log type.", allowedvalues = {
					"DEBUG", "INFO", "ERROR", "FATAL" }) String type);

	@ApiMethod(path = "/api/log/countbytext/{text}", verb = ApiVerb.GET, description = "Counts the number of log entries for a given text. Parital text is also allowed.", produces = { MediaType.APPLICATION_JSON }, consumes = { MediaType.APPLICATION_JSON })
	@ApiHeaders(headers = {
			@ApiHeader(name = "signature", description = "Authentication signature."),
			@ApiHeader(name = "public-key", description = "Public key of the application.") })
	@ApiResponseObject
	long countByText(
			@ApiParam(name = "text", required = true, description = "Log text.") String text);

	@ApiMethod(path = "/api/log/countbydaterange/{start}/{end}", verb = ApiVerb.GET, description = "Counts the number of log entries between a date range.", produces = { MediaType.APPLICATION_JSON }, consumes = { MediaType.APPLICATION_JSON })
	@ApiHeaders(headers = {
			@ApiHeader(name = "signature", description = "Authentication signature."),
			@ApiHeader(name = "public-key", description = "Public key of the application.") })
	@ApiResponseObject
	long countByDateRange(

			@ApiParam(name = "start", required = true, description = "Start Date", format = "yyyy-MM-dd") Date start,
			@ApiParam(name = "end", required = true, description = "End Date", format = "yyyy-MM-dd") Date end);

}